<?php
include_once("models/NguoiDung.php");

class CoVanHocTap extends NguoiDung {
	protected $hocVi;
	protected $soDT;
	protected $danhSachLop;
	
	public function __construct($new = false) {
		parent::__construct($new);
		$this->prefix = "CVHT_";
		$this->table = "CO_VAN_HOC_TAP";
	}
	
	public function setHocVi($hocVi) { $this->hocVi = $hocVi; }
	public function getHocVi() { return $this->hocVi; }
	
	public function setSoDT($soDT) { $this->soDT = $soDT; }
	public function getSoDT() { return $this->soDT; }
	
	public function setMaLop($lopMaSo) { $this->lopMaSo = $lopMaSo; }
	public function getMaLop() { return $this->lopMaSo; }
 
	public function themCoVanHocTap() {
		return $this->themNguoiDung(array("CVHT_SO_DT" => $this->soDT, "CVHT_HOC_VI" => $this->hocVi));
	}
	
	public function suaCoVanHocTap() {
		return $this->suaNguoiDung(array("CVHT_SO_DT" => $this->soDT, "CVHT_HOC_VI" => $this->hocVi));
	}
	
	public function xoaCoVanHocTap() {
		return $this->xoaNguoiDung();
	}
	
	public function layThongTinNguoiDung() {
		$data = array(
					$this->prefix . "HO as HO",
					$this->prefix . "TEN as TEN",
					"date_format(" . $this->prefix . "NGAY_SINH, '%d-%m-%Y') as NGAY_SINH",
					$this->prefix . "PHAI as PHAI",
					$this->prefix . "EMAIL as EMAIL",
					"CVHT_SO_DT",
					"CVHT_HOC_VI"
					);
				
		$result = $this->select($this->table, $data, $this->prefix . "MA_SO = " . $this->maSo);		
		$row = mysql_fetch_assoc($result);
		$this->ho = $row['HO'];
		$this->ten = $row['TEN'];
		$this->ngaySinh = $row['NGAY_SINH'];
		$this->phai = $row['PHAI'];
		$this->email = $row['EMAIL'];
		$this->soDT = $row['CVHT_SO_DT'];
		$this->hocVi = $row['CVHT_HOC_VI'];
		
		//$this->taoDanhSachLop();
	}
	
	private function taoDanhSachLop() {
		$this->danhSachLop = array();
		$result = $this->select("LOP", array("LOP_MA_SO", "LOP_TEN", "KH_MA_SO"),
								"CVHT_MA_SO = " . $this->maSo . " ORDER BY LOP_MA_SO");
		while ($row = mysql_fetch_assoc($result)) {
			$this->danhSachLop[] = $row;
		}
	}
	
	public function layDanhSachLop($renew = false) {
		if ($renew)
			$this->taoDanhSachLop();
		return $this->danhSachLop;
	}
	
	public function laQuanLyCuaLop($maLop) {
		foreach($this->danhSachLop as $lop)
			if ($lop['LOP_MA_SO'] == $maLop)
				return true;
		return false;
	}
}
?>